<%-- 
    Document   : main
    Created on : Jul 5, 2011, 7:38:47 PM
    Author     : Admin
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="javax.naming.*" %>
<%@page import="ejb.user.*" %>
<%@page import="ejb.object.*" %>
<%@page import="client.common.*" %>
<%@page import="java.util.ArrayList"%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello World!</h1>

        <form method="post" action="UserServlet">
        <table border="1">

            <tr><td>ID</td><td>Name</td><td>Role</td><td>Edit</td><td>Delete</td></tr>


<%
        try {

                Config.settingSystemPropertiesForSessionBean();
                Context ctx=new InitialContext();
                Object ref=ctx.lookup("User");
                UserRemoteHome home=(UserRemoteHome)ref;


                try{
                    UserRemote remote=home.create();
                   ArrayList list= remote.findUsers();
                   
                   for(int i=0;i<list.size();i++){

                    out.print("<tr>");
                            out.print("<td>"+((UserOBJ)list.get(i)).getID()+"</td>");

                            out.print("<td>"+((UserOBJ)list.get(i)).getName()+"</td>");


                            out.print("<td>"+((UserOBJ)list.get(i)).getRole()+"</td>");

                            out.print("<td><a href='edit.jsp?id="+((UserOBJ)list.get(i)).getID()+"'>Edit</a></td>");
                            out.print("<td><a href='delete.jsp?id="+((UserOBJ)list.get(i)).getID()+"'>Delete</a></td>");
                            
                    out.print("</tr>");
                   }
                }
                catch(Exception ex){
                    ex.printStackTrace();
                }
          }
          catch(ConfigException configException){
            configException.printStackTrace();
          }

        catch(Exception ex){


        }
        %>
        </table>
        </form>
    </body>
</html>
